<template>
  <div>
    <div>
      <el-button size="mini" type="primary" plain @click="Button_on_NewOrder()">新建采购订单</el-button>
      <el-button
        size="mini"
        type="primary"
        plain
        @click="Button_on_DeleteOrder()"
        :disabled="buttons_canbeused.delete"
      >删除采购订单</el-button>
      <el-divider direction="vertical"></el-divider>
      <el-button
        size="mini"
        type="primary"
        plain
        @click="Button_on_ConfirmOrder()"
        :disabled="buttons_canbeused.confirm"
      >审核</el-button>
      <el-button
        size="mini"
        type="primary"
        plain
        @click="Button_on_DisConfirmOrder()"
        :disabled="buttons_canbeused.disconfirm"
      >取消审核</el-button>
      <el-button
        size="mini"
        type="primary"
        plain
        @click="Button_on_Generate()"
        :disabled="buttons_canbeused.generate"
      >生成采购入库单</el-button>
    </div>
    <div class="top-check">
      <el-form :inline="true" :model="checkForm" size="mini">
        <el-form-item label="状态">
          <el-select v-model="checkForm.billstatu">
            <el-option label="全部" value=""></el-option>
            <el-option label="已审核" value="已审核"></el-option>
            <el-option label="申请入库中" value="申请入库中"></el-option>
            <el-option label="完成入库" value="完成入库"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="单号">
          <el-input v-model="checkForm.ref"></el-input>
        </el-form-item>
        <el-form-item label="交货日期">
         <el-date-picker
            type="date"
            placeholder="选择日期"
            v-model="checkForm.dealdate"
            value-format="yyyy-MM-dd"
            style="width: 100%;"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="供应商">
           <el-input v-model="checkForm.suppliername"></el-input>
        </el-form-item>
        <el-form-item label="付款方式">
          <el-select v-model="checkForm.paymenttype">
            <el-option label="现金付款" value="现金付款"></el-option>
            <el-option label="在线支付" value="在线支付"></el-option>
            <el-option label="货到付款" value="货到付款"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="CheckSubmit">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="clear_find">清空查询条件</el-button>
        </el-form-item>
      </el-form>
    </div>
    <div class="bill">
      <el-table
        :data="App_Bill_List.list"
        @row-click="Select_Bill_Row"
        border
        :stripe="true"
        :header-cell-style="{background:'#e3e5e9',color:'#606266'}"
        :row-style="{height:'5px'}"
        :cell-style="{padding:'5px 0'}"
        tooltip-effect="light"
        highlight-current-row
        style="width: 100%;"
        height="400"
      >
        <el-table-column prop="billstatu" label="状态" width="150"></el-table-column>
        <el-table-column prop="ref" label="采购订单号" width="150"></el-table-column>
        <el-table-column prop="dealdate" label="交货日期" width="150"></el-table-column>
        <el-table-column show-overflow-tooltip prop="dealaddress" label="交货地址" width="250"></el-table-column>
        <el-table-column show-overflow-tooltip prop="suppliername" label="供应商" width="250"></el-table-column>
        <el-table-column show-overflow-tooltip prop="contact" label="供应商联系人" width="125"></el-table-column>
        <el-table-column show-overflow-tooltip prop="phone" label="供应商电话" width="115"></el-table-column>
        <el-table-column prop="goodsmoney" label="采购金额" width="95"></el-table-column>
        <el-table-column prop="tax" label="税金" width="95"></el-table-column>
        <el-table-column prop="moneyandtax" label="价税合计" width="95"></el-table-column>
        <el-table-column prop="paymenttype" label="付款方式" width="95"></el-table-column>
        <el-table-column prop="bizusername" label="业务员" width="95"></el-table-column>
        <el-table-column show-overflow-tooltip prop="orgname" label="组织机构" width="95"></el-table-column>
        <el-table-column show-overflow-tooltip prop="memo" label="备注" width="105"></el-table-column>
      </el-table>
    </div>
    <div class="diver"></div>
    <div class="detail">
      <el-tabs type="border-card">
        <el-tab-pane>
          <span slot="label">
            <i class="el-icon-s-order"></i>
            单号:{{DetailContentTitle.ref}} 供应商:{{DetailContentTitle.suppliername}}
          </span>
          <div>
            <el-table
              border
              :data="App_DetailBill_List.list"
              :stripe="true"
              :header-cell-style="{background:'#e3e5e9',color:'#606266'}"
              :row-style="{height:'5px'}"
              :cell-style="{padding:'5px 0'}"
              tooltip-effect="light"
              highlight-current-row
              style="width: 100%;"
              height="200"
            >
              <el-table-column  label="序号" width="50">
                <template slot-scope="scope">
                  <span>{{scope.$index + 1}}</span>
                </template>
              </el-table-column>
              <el-table-column  prop="code" label="商品编码" width="150"></el-table-column>
              <el-table-column prop="name" label="商品名称" width="200"></el-table-column>
              <el-table-column show-overflow-tooltip prop="spec" label="规格型号" width="250"></el-table-column>
              <el-table-column show-overflow-tooltip prop="count" label="采购数量" width="95"></el-table-column>
              <el-table-column show-overflow-tooltip prop="unitname" label="单位" width="125"></el-table-column>
              <el-table-column prop="price" label="采购单价" width="95"></el-table-column>
              <el-table-column prop="money" label="采购金额" width="95"></el-table-column>
              <el-table-column prop="taxrate" label="税率（%）" width="95"></el-table-column>
              <el-table-column prop="tax" label="税金" width="95"></el-table-column>
              <el-table-column prop="moneywithtax" label="价税合计" width="95"></el-table-column>
              <el-table-column show-overflow-tooltip prop="moneywithtax" label="备注" width="95"></el-table-column>
            </el-table>
          </div>
            </el-tab-pane>
       
      </el-tabs>
    </div>
    <div class="clear"></div>
    <DialogOfAddOrder
      v-if="dialog.add_order"
      @dialog-close="dialog.add_order = false"
      @refresh="Refresh_Bill_List"
      :form="App_Bill_List.Select_Row"
    ></DialogOfAddOrder>
    <DialogOfDeleteOrder
      v-if="dialog.delete_order"
      @dialog-close="dialog.delete_order = false"
      @refresh="Refresh_Bill_List"
      :form="App_Bill_List.Select_Row"
    ></DialogOfDeleteOrder>
    <DialogOConfirmOrder
      v-if="dialog.confirm_order"
      @dialog-close="dialog.confirm_order = false"
      @refresh="Refresh_Bill_List"
      :form="App_Bill_List.Select_Row"
    ></DialogOConfirmOrder>
    <DialogODisconfirmOrder
      v-if="dialog.disconfirm_order"
      @dialog-close="dialog.disconfirm_order = false"
      @refresh="Refresh_Bill_List"
      :form="App_Bill_List.Select_Row"
    ></DialogODisconfirmOrder>
    <DialogOfGenerate
      v-if="dialog.generate"
      @dialog-close="dialog.generate = false"
      @refresh="Refresh_Bill_List"
      :form="App_Bill_List.Select_Row"
    ></DialogOfGenerate>
  </div>
</template>

<script>
import DialogOfAddOrder from "./order/add";
import DialogOfDeleteOrder from "./order/delete";
import DialogOConfirmOrder from "./order/confirm";
import DialogODisconfirmOrder from "./order/disconfirm";
import DialogOfGenerate from "./order/generate";
export default {
  components: {
    DialogOfAddOrder,
    DialogOfDeleteOrder,
    DialogOConfirmOrder,
    DialogODisconfirmOrder,
    DialogOfGenerate
  },
  data() {
    return {
      dialog: {
        add_order: false,
        delete_order: false,
        confirm_order:false,
        disconfirm_order:false,
        generate:false,
      },
      buttons_canbeused: {
        delete: true,
        confirm: true,
        disconfirm: true,
        generate: true
      },
      checkForm: {
        status: "all"
      },
      DetailContentTitle: {
        ref: "无",
        suppliername: "无"
      },
      App_Bill_List: {
        list: [],
        Select_Row: {}
      },
      App_DetailBill_List: {
        list: [],
        Select_Row: {}
      }
    };
  },
  created() {
    this.Refresh_Bill_List();
    this.Refresh_Billdetail_List(1);
  },
  methods: {
    clear_find(){
      this.checkForm={}
    },
    CheckSubmit() {
       this.$http.post("order/search",this.checkForm).then(response =>{
        this.App_Bill_List.list = response.data
      })
    },
    Refresh_Bill_List() {
      this.$http.get("order/list").then(response => {
        this.App_Bill_List.list = response.data;
      });
    },
    Refresh_Billdetail_List(order_id) {
      // window.console.log(order_id);

      this.$http
        .post("orderdetail/somelist", { orderid: order_id })
        .then(response => {
          this.App_DetailBill_List.list = response.data;
        });
    },
    Select_Bill_Row(Row) {
      window.console.log('sdsss');

      this.Refresh_Billdetail_List(Row.id);
      this.DetailContentTitle = JSON.parse(JSON.stringify(Row));
      this.App_Bill_List.Select_Row = JSON.parse(JSON.stringify(Row));
      window.console.log(Row.billstatu == "待审核");
      if (Row.billstatu == "待审核") {
        this.buttons_canbeused.delete = false;
        this.buttons_canbeused.confirm = false;
        this.buttons_canbeused.disconfirm = true;
        this.buttons_canbeused.generate = true;
      }
      if (Row.billstatu == "已审核") {
        this.buttons_canbeused.delete = true;
        this.buttons_canbeused.confirm = true;
        this.buttons_canbeused.disconfirm = false;
        this.buttons_canbeused.generate = false;
      }
      if (Row.billstatu == "申请入库中") {
        this.buttons_canbeused.delete = true;
        this.buttons_canbeused.confirm = true;
        this.buttons_canbeused.disconfirm = true;
        this.buttons_canbeused.generate = true;
      }
      if (Row.billstatu == "完成入库") {
        this.buttons_canbeused.delete = true;
        this.buttons_canbeused.confirm = true;
        this.buttons_canbeused.disconfirm = true;
        this.buttons_canbeused.generate = true;
      }
    },
    Check_Bill_Row() {
      if (
        this.App_Bill_List.Select_Row.id == null ||
        this.App_Bill_List.Select_Row.id == ""
      ) {
        this.$message.error("请选择一个采购订单");
        return false;
      }
      return true;
    },
    Button_on_NewOrder() {
      this.dialog.add_order = true;
      window.console.log(this.App_DetailBill_List);
    },
    Button_on_DeleteOrder() {
      if (this.Check_Bill_Row()) {
        this.dialog.delete_order = true;
      }
    },
    Button_on_ConfirmOrder() {
      if (this.Check_Bill_Row()) {
        this.dialog.confirm_order = true
      }
    },
    Button_on_DisConfirmOrder() {
      if (this.Check_Bill_Row()) {
        this.dialog.disconfirm_order = true
      }
    },
    Button_on_Generate() {
      if (this.Check_Bill_Row()) {
        this.dialog.generate = true
      }
    },
  }
};
</script>

<style >
.el-table__header tr,
.el-table__header th {
  padding: 0;
  height: 20px;
}
.el-table__body tr,
.el-table__body td {
  padding: 0;
  height: 20px;
}
.bottom-detail {
  height: auto;
}
.diver {
  height: 10px;
  border-radius: 5px;
  margin: 4px 0;
  background: #f1f0f7;
}
</style>>
